#include <iostream>
#include <string>
#include <gtest/gtest.h>
#include "../mqserver/binding.hpp"
using namespace std;
rbmq::BindingManager::ptr bmg;

class BindingTest : public testing::Environment {
public :
    virtual void SetUp() override {
        bmg = make_shared<rbmq::BindingManager>("./data/meta.db");
        // cout << "---------------------打开数据库----------------------" << endl;
    }
    virtual void TearDown() {
        // bmg->clear();
    }

private :
};

TEST(binding_test, insert_test) {
    bmg->bind("exchange1", "queue1", "music.news", true);
    bmg->bind("exchange2", "queue2", "music.news", true);
    bmg->bind("exchange3", "queue3", "music.news", true);
    bmg->bind("exchange4", "queue4", "music.news", true);
    bmg->bind("exchange4", "queue3", "music.news", true);
    bmg->bind("exchange4", "queue2", "music.news", true);
    bmg->bind("exchange4", "queue1", "music.news", true);
    // ASSERT_EQ(bmg->size(), 4);
    ASSERT_EQ(bmg->exists("exchange4", "queue4"), true);
    ASSERT_EQ(bmg->exists("exchange5", "queue5"), false);
}


TEST(binding_test, select_test) {
    rbmq::MsQueueBindingMap map = bmg->getExchangeBindings("exchange4");
    ASSERT_EQ(map.size(), 4);
    ASSERT_NE(map.find("queue4"), map.end());
    ASSERT_NE(map.find("queue3"), map.end());
    ASSERT_NE(map.find("queue2"), map.end());
    ASSERT_NE(map.find("queue1"), map.end());
}

// TEST(binding_test, delete_test) {
//     bmg->removeMsQueueBindings("queue3", true);
//     ASSERT_EQ(bmg->size(), 3);
// }

// TEST(binding_test, select_test) {
//     ASSERT_NE(bmg->getBinding("exchange1", "queue1"), nullptr);
//     ASSERT_NE(bmg->getBinding("exchange2", "queue2"), nullptr);
//     ASSERT_NE(bmg->getBinding("exchange3", "queue3"), nullptr);
//     ASSERT_NE(bmg->getBinding("exchange4", "queue4"), nullptr);
//     // ASSERT_NE(bmg->getBinding("exchange5", "queue5"), nullptr);
// }

// TEST(binding_test, delete_test) {
//     bmg->unbind("exchange3", "queue3", true);
//     ASSERT_EQ(bmg->size(), 3);
// }

int main(int argc, char* args[]) {
    testing::InitGoogleTest(&argc, args);   
    testing::AddGlobalTestEnvironment(new BindingTest());
    RUN_ALL_TESTS();
    return 0;
}